//package org.javaboy.grpc.demo;
//
//import com.lglbc1.hello.OpenAPIGrpc;
//import com.lglbc1.hello.Request;
//import com.lglbc1.hello.Response;
//import io.grpc.ManagedChannel;
//import io.grpc.ManagedChannelBuilder;
//import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
//import io.grpc.stub.StreamObserver;
//
///**
// * @author: jiaxiangen
// * @Date: 2025/6/3 15:48
// * @Version 1.0
// * @Description: GRPC client
// */
//public class Client {
//    public static void main(String[] args) {
//        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9090)
//                .intercept(new ClientLoggingInterceptor())
//                .usePlaintext()
//                .build();
//
//        OpenAPIGrpc.OpenAPIStub openAPIStub = OpenAPIGrpc.newStub(channel);
//        Request request = Request.newBuilder()
//                .setName("乐哥聊编程")
//                .build();
//        StreamObserver<Response> responseObserver = new StreamObserver<Response>() {
//            @Override
//            public void onNext(Response response) {
//                System.out.println("Received response: " + response.getMessage());
//            }
//
//            @Override
//            public void onError(Throwable t) {
//                System.err.println("Error: " + t.getMessage());
//            }
//
//            @Override
//            public void onCompleted() {
//                System.out.println("Server completed.");
//            }
//        };
//        StreamObserver<Request> requestObserver = openAPIStub.bidirectionalStreaming(responseObserver);
//        for (int i = 0; i < 5; i++) {
//            Request request2 = Request.newBuilder()
//                    .setName("Request " + (i + 1))
//                    .build();
//            requestObserver.onNext(request2);
//        }
//
//        // 结束请求流
//        requestObserver.onCompleted();
//        // 等待完成
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        channel.shutdown();
//    }
//}
